﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Collections.Generic;

#region 参数定义
/// <summary>
/// F10参数类
/// modify by :zhu.xiaobing
/// modify time :2012-08-20
/// </summary>
public class F10ParamEntity
{
    public F10ParamEntity(int full)
    {
        this.Full = full;
    }

    public F10ParamEntity(string prefix, string tableName, int full)
    {
        this.Prefix = prefix;
        this.TableName = tableName;
        this.Full = full;
    }

    /// <summary>
    /// url前缀
    /// </summary>
    public string Prefix { get; set; }

    /// <summary>
    /// url里面的资源表名
    /// </summary>
    public string TableName { get; set; }

    /// <summary>
    /// 跳过的count
    /// </summary>
    public int Skip { get; set; }

    /// <summary>
    /// 限制取的count
    /// </summary>
    public int Limit { get; set; }

    /// <summary>
    /// 模式
    /// </summary>
    protected int Full { get; set; }

    /// <summary>
    /// 过滤字段
    /// </summary>
    public string Fields { get; set; }

    /// <summary>
    /// 过滤条件
    /// </summary>
    public List<string> Filters { get; set; }

    /// <summary>
    /// 排序字段
    /// </summary>
    public string OrderBy { get; set; }

    /// <summary>
    /// 唯一字段的值
    /// </summary>
    public string Distinct { get; set; }

    public override string ToString()
    {
        var sbTemp = new StringBuilder();
        if (Full >= 0)
        {
            sbTemp.Append("&full=" + this.Full);
        }
        if (this.Distinct != null && this.Distinct.Length > 0)
        {
            sbTemp.Append("&Distinct=" + this.Distinct);
        }

        if (this.Skip > 0)
        {
            sbTemp.Append("&skip=" + this.Skip);
        }
        if (this.Limit > 0)
        {
            sbTemp.Append("&limit=" + this.Limit);
        }
        if (this.Fields != null && this.Fields.Length > 0)
        {
            sbTemp.Append("&field=" + Fields);
        }
        if (this.Filters != null && Filters.Count > 0)
        {
            foreach (var f in this.Filters)
            {
                sbTemp.Append("&filter-" + f);
            }
        }
        if (this.OrderBy != null && this.OrderBy.Length > 0)
        {
            sbTemp.Append("&sort=" + OrderBy);
        }

        return sbTemp.ToString().TrimStart('&');
    }

    /// <summary>
    /// 设置limit参数
    /// </summary>
    /// <param name="limit">取的记录条数</param>
    /// <returns>参数实例对象</returns>
    public F10ParamEntity LimitExt(int limit)
    {
        this.Limit = limit;

        return this;
    }

    /// <summary>
    /// 设置Skip参数
    /// </summary>
    /// <param name="skip">跳过的记录数</param>
    /// <returns>参数实例对象</returns>
    public F10ParamEntity SkipExt(int skip)
    {
        this.Skip = skip;

        return this;
    }
}
#endregion
